package com.cscp.javastudy.basic.reflect;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

public class WorkTest {

    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        Class c1 = Class.forName("com.cscp.javastudy.basic.reflect.Worker");
        // 通过反射获取注解
        Annotation[] annotations = c1.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }

        // 获得注解的值
        MyTable myTableAnno = (MyTable)c1.getAnnotation(MyTable.class);
        System.out.println(myTableAnno.name());

        // 获得指定的注解
        Field f = c1.getDeclaredField("name");
        MyField specificField = f.getAnnotation(MyField.class);
        System.out.println(specificField.columnName());
        System.out.println(specificField.type());
        System.out.println(specificField.length());

    }

}
